<?php
/**
 * Created by PhpStorm.
 * User: xi
 * Date: 2020-05-02
 * Time: 16:54
 */

namespace app\api\service;


use app\admin\model\Roomclean;
use app\admin\model\Shop;
use app\admin\model\Shopmeituan;
use app\admin\model\Shoporderprofit;
use app\admin\model\Shoproombook;
use app\admin\model\Shopstaff;
use app\admin\model\Userdoucode;
use app\admin\model\Usermeituancode;
use app\admin\model\Userorderprofit;
use app\admin\model\Usertuan;
use app\admin\model\Userwithdraw;

class LockService
{


    public function getPassword($param = array()){

        $url = "https://cnapi.sciener.com/v3/keyboardPwd/get";
        $tokenUrl = "https://cnapi.sciener.com/oauth2/token";
        $tokenReq = array();
        $tokenReq['clientId'] = "4122b7859d9745a2bc32cdc084ca0231";
        $tokenReq['clientSecret'] = "07aa420424861bb837f58a33867b49d7";
        $tokenReq['username'] = "18672675467";
        $tokenReq['password'] = md5("johnwang1990");

        $result = postCurl($tokenUrl,$tokenReq);

        $token = $result['access_token'];


        $startDate =$param['startDate'].'.123'; // 指定日期
        $startTimestamp = (float) sprintf('%.0f', strtotime($startDate) * 1000 + explode(' ', microtime())[0] * 1000);

        $endDate =$param['endDate'].'.123'; // 指定日期
        $endTimestamp = (float) sprintf('%.0f', strtotime($endDate) * 1000 + explode(' ', microtime())[0] * 1000);


        $keyReq = array();
        $keyReq['accessToken'] = $token;
        $keyReq['clientId'] = "4122b7859d9745a2bc32cdc084ca0231";
        $keyReq['lockId'] = $param['lockId'];
        $keyReq['keyboardPwdType'] = 3;
        $keyReq['startDate'] = $startTimestamp;
        $keyReq['endDate'] = $endTimestamp;
        $keyReq['date'] = getMillisecond();


        $result = postCurl($url,$keyReq);
        if (isset($result['keyboardPwd'])){
            return $result['keyboardPwd'];
        }else{
            return "";
        }

    }


    public function openLock($param = array()){

        $url = "https://cnapi.sciener.com/v3/lock/unlock";
        $tokenUrl = "https://cnapi.sciener.com/oauth2/token";
        $tokenReq = array();
        $tokenReq['clientId'] = "4122b7859d9745a2bc32cdc084ca0231";
        $tokenReq['clientSecret'] = "07aa420424861bb837f58a33867b49d7";
        $tokenReq['username'] = "18672675467";
        $tokenReq['password'] = md5("johnwang1990");

        $result = postCurl($tokenUrl,$tokenReq);
        $token = $result['access_token'];


//        $startDate =$param['startDate'].'.123'; // 指定日期
//        $startTimestamp = (float) sprintf('%.0f', strtotime($startDate) * 1000 + explode(' ', microtime())[0] * 1000);
//
//        $endDate =$param['endDate'].'.123'; // 指定日期
//        $endTimestamp = (float) sprintf('%.0f', strtotime($endDate) * 1000 + explode(' ', microtime())[0] * 1000);
//

        $keyReq = array();
        $keyReq['accessToken'] = $token;
        $keyReq['clientId'] = "4122b7859d9745a2bc32cdc084ca0231";
        $keyReq['lockId'] = $param['lockId'];
        $keyReq['date'] = getMillisecond();


        $result = postCurl($url,$keyReq);
        return $result;


    }

}